package service.pqueue;

import java.util.concurrent.ConcurrentLinkedQueue;

public class PQueue implements IPQueue {
	private long polls = 0;
	private long offers = 0;
	private ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>();

	public boolean offer(String key, String msg) {
		if (offers >= Long.MAX_VALUE) {
			offers = 0;
		}
		offers++;
		return queue.offer(msg);
	}

	public String poll() {
		if (polls >= Long.MAX_VALUE) {
			polls = 0;
		}
		polls++;
		return queue.poll();
	}

	public int statsLen() {
		return queue.size();
	}

	public long statsOffers() {
		return offers;
	}

	public long statsPolls() {
		return polls;
	}

	public void flush() {
		queue.clear();
	}
}
